package com.jinxin.platform.cdsideparkmgr.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.annotation.UnLoginForUser;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdsideparkmgr.bean.CdsideparkmgrParkRecord;
import com.jinxin.platform.cdsideparkmgr.service.ICdsideparkmgrParkRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-09-15
 * @Author: Lingnan
 **/
@APCOSApi(value = "路边停车记录接口", developers = {"lingnan"}, description = "路边停车记录接口")
@RestController
@RequestMapping("/cdsideparkmgr/cdsideparkmgrParkRecord")
@Slf4j
public class CdsideparkmgrParkRecordController {
    @Autowired
    ICdsideparkmgrParkRecordService parkRecordService;

    @APCOSApiOperation(value = "分页查询记录", developers = {"lingnan"}, description = "分页查询记录",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit,
                                   @RequestParam(required = false,name = "carNo")String carNo,
                                   @RequestParam(name = "projectId")String projectId,
                                   @RequestParam(required = false,name = "direction")String direction,
                                   @RequestParam(required = false,name = "area")String area,
                                   @RequestParam(required = false,name = "stall")String stall,
                                   @RequestParam(required = false,name = "category")String category,
                                   String startDate,String endDate,String startDate2,String endDate2){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg","success");
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("carNo", carNo);
        param.put("projectId", projectId);
        param.put("area", area);
        param.put("direction", direction);
        param.put("stall", stall);
        param.put("category", category);
        param.put("startDate", startDate);
        param.put("endDate", endDate);
        param.put("startDate2", startDate2);
        param.put("endDate2", endDate2);
        resultMap.put("count", parkRecordService.listPageCount(param));
        resultMap.put("data", parkRecordService.listPage(param));
        return resultMap;
    }

    @APCOSApiOperation(value = "保存或更新记录", developers = {"lingnan"}, description = "保存或更新记录",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody CdsideparkmgrParkRecord record){
        return parkRecordService.saveOrUpdate(record);
    }

    @APCOSApiOperation(value = "获取位置列表", developers = {"lingnan"}, description = "获取位置列表",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/loadAreaList")
    public JsonResult loadAreaList(String projectId){
        return JsonResult.ok(parkRecordService.listAreaOptions(projectId));
    }

    @APCOSApiOperation(value = "获取车位列表", developers = {"lingnan"}, description = "获取车位列表",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/loadStallList")
    public JsonResult loadStallList(String projectId){
        return JsonResult.ok(parkRecordService.listStallOptions(projectId));
    }

    @APCOSApiOperation(value = "根据项目id查询车辆类别", developers = {"lingnan"}, description = "根据项目id查询车辆类别",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/listCategory")
    public JsonResult listCategory(@RequestParam(name = "projectId")String projectId){
        return JsonResult.ok(parkRecordService.listCategory(projectId));
    }

}
